﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace 玩具商城管理系统
{
    public partial class people : Form
    {
        public people()
        {
            InitializeComponent();
        }
        SqlDataAdapter daorderT ;
        DataSet ds = new DataSet();
        void init()
        {
            DB.GetCn();
            string str = "select orderT_id,orderT_cid,orderT_address,orderT_city,orderT_code,orderT_phone,order_Note from orderT where orderT_cid='" + login.username+"'";
            daorderT = new SqlDataAdapter(str, DB.cn);
            daorderT.Fill(ds, "product_info");


        }
        void showAll()
        {
            DataView dvProduct = new DataView(ds.Tables["product_info"]);
            dgvshopcar.DataSource = dvProduct;
            this.dgvshopcar.Columns[1].HeaderText = "订单编号";
            this.dgvshopcar.Columns[2].HeaderText = "用户名称";
            this.dgvshopcar.Columns[3].HeaderText = "用户省份";
            this.dgvshopcar.Columns[4].HeaderText = "用户城市";
            this.dgvshopcar.Columns[5].HeaderText = "地区邮编";
            this.dgvshopcar.Columns[6].HeaderText = "用户地址";
            this.dgvshopcar.Columns[7].HeaderText = "用户备注";
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string str = "";
            int i = comboBox1.SelectedIndex;
            switch (i)
            {
                case 0:
                    str = " 我要修改送货地址";
                    label2.Visible = true;
                    label3.Visible = false;
                    label4.Visible = false;
                    label5.Visible = false;
                    break;
                case 1:
                    str = " 我购买错误了需要重新购买商品";
                    label3.Visible = true;
                    label2.Visible = false;
                    label4.Visible = false;
                    label5.Visible = false;
                    break;
                case 2:
                    str = "我突然间不想购买该商品了";
                    label4.Visible = true;
                    label2.Visible = false;
                    label3.Visible = false;
                    label5.Visible = false;
                    break;
                case 3:
                    str = " 我选择错商品款式需要重新购买 ";
                    label5.Visible = true;
                    label2.Visible = false;
                    label3.Visible = false;
                    label4.Visible = false;
                    break;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("您对这次的服务满意吗", "评价", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dr == DialogResult.OK)
            {
                this.Close();
            }
            else
            {
                this.Close();
            }
            
        }

        private void button4_Click(object sender, EventArgs e)
        {
            
            
            for (int i = 0; i < dgvshopcar.Rows.Count; i++)
            {
              
                if (dgvshopcar.Rows[i].Cells["acCode"].EditedFormattedValue.ToString() == "True")
                {
                    int a = dgvshopcar.CurrentRow.Index;
                    string str = dgvshopcar.Rows[a].Cells["orderT_id"].Value.ToString();
                    DataRow[] ProRows = ds.Tables["product_info"].Select("orderT_id='" + str + "'");
                    ProRows[0]["order_Note"] = txtcontent.Text;
                    DB.GetCn();
                    string sdr = "UPDATE orderT set order_Note = '" + txtcontent.Text + "' where orderT_id='"+str+"'";
                    DB.sqlEx(sdr);
                    MessageBox.Show("已提交");
                    break;
                }
                if (dgvshopcar.Rows[i].Cells["acCode"].EditedFormattedValue.ToString() == "False")
                {
                    MessageBox.Show("请选择你要添加备注的订单");
                    break;
                }
            }
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
           MessageBox.Show("抱歉为你解决您的问题这边您可以拨打人工客服电话13686936586", "提示");
            
                this.Close();
            
        }

        private void dgvshopcar_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            txtcontent.Text = dgvshopcar.CurrentRow.Cells["order_Note"].Value.ToString();
           
        }

        private void people_Load(object sender, EventArgs e)
        {

            init();
            showXz();
            showAll();
        }
        void showXz()
        {
            DataGridViewCheckBoxColumn acCode = new DataGridViewCheckBoxColumn();
            acCode.Name = "acCode";
            acCode.HeaderText = "选择";
            dgvshopcar.Columns.Add(acCode);

        }
    }
}
